package com.top.art.manager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.beust.jcommander.internal.Sets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.top.art.bo.ExaminationPaperPageBO;
import com.top.art.bo.PaperBO;
import com.top.art.bo.PaperQueryBO;
import com.top.art.bo.UploadPaperBO;
import com.top.art.constants.CommonErrorCodeEnum;
import com.top.art.converter.ExaminationPaperConverter;
import com.top.art.converter.ExamineeInfoConverter;
import com.top.art.entity.Aggregation;
import com.top.art.entity.Constants;
import com.top.art.entity.ExaminationPaper;
import com.top.art.entity.ExamineeInfo;
import com.top.art.enums.CourseEnum;
import com.top.art.exception.ArtException;
import com.top.art.mapper.ExaminationPaperMapper;
import com.top.art.mapper.ExamineeInfoMapper;
import com.top.art.mapper.RulerMapper;
import com.top.art.mapper.StudioInfoMapper;
import com.top.art.service.*;
import com.top.art.tool.AliYunCode;
import com.top.art.tool.AuthTool;
import com.top.art.tool.Constant;
import com.top.art.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

import static com.top.art.tool.Tool.defaultInteger;
import static com.top.art.tool.Tool.notNullAndEmpty;
import static java.util.stream.Collectors.toList;


/**
 * The type Examination paper manager.
 *
 * @author hjh
 * @version 2020 /10/5-10:54
 */
@Slf4j
@Component
public class ExaminationPaperManager {


    @Autowired
    ExaminationPaperMapper examinationPaperMapper;
    @Autowired
    IRulerService rulerService;
    @Autowired
    ExamineeInfoMapper examineeInfoMapper;
    @Autowired
    RulerMapper rulerMapper;
    @Autowired
    IStudioInfoService iStudioInfoService;
    @Autowired
    StudioInfoMapper studioInfoMapper;

    @Autowired
    IConstantsService iConstantsService;

    /**
     * service
     */
    @Autowired
    private IExaminationPaperService examinationPaperService;
    @Autowired
    private IExamineeInfoService examineeInfoService;
    @Resource
    private ExamineeInfoConverter examineeInfoConverter;
    /**
     * Transaction
     */
    @Resource
    private DataSourceTransactionManager transactionManager;
    @Resource
    private ExaminationPaperConverter examinationPaperConverter;

    /**
     * Count paper count vo.
     *
     * @return the paper count vo
     */
    public PaperCountVO count(String studioCode) {
        PaperCountVO vo = new PaperCountVO();
        List<Map<String, Object>> counts = examinationPaperMapper.countByStudioCode(studioCode);
        Map<String, Long> countsMap = new HashMap<>();
        counts.forEach(i -> countsMap.put(i.get("course").toString(), Long.valueOf(String.valueOf(i.get("cnt")))));
        vo.setColor(countsMap.getOrDefault("色彩", 0L));
        vo.setSketch(countsMap.getOrDefault("素描", 0L));
        vo.setWriting(countsMap.getOrDefault("速写", 0L));
        vo.setCompose(countsMap.getOrDefault("构成", 0L));
        return vo;
    }


    /**
     * Page page.
     *
     * @param bo the bo
     * @return the page
     */
    public Page<ExaminationPaperVO> page(ExaminationPaperPageBO bo) {
        Page<ExaminationPaperVO> page = new Page<>(bo.getCurrent(), bo.getSize());
        IPage<ExamineeInfo> infoIPage = examineeInfoService.page(bo);
        page.setTotal(infoIPage.getTotal());
        page.setRecords(infoIPage.getRecords().stream().map(x -> {
            ExaminationPaperVO vo = examineeInfoConverter.do2vo(x);
            Map<String, ExaminationPaper> map = examinationPaperService.list(Wrappers.<ExaminationPaper>lambdaQuery()
                    .eq(ExaminationPaper::getAdmissionTicketCode, x.getAdmissionTicketCode())
                    .eq(notNullAndEmpty(bo.getAccount()), ExaminationPaper::getAccount, bo.getAccount())
                    .eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade())
                    .isNull(bo.getStatus() != null && bo.getStatus() == 0, ExaminationPaper::getScore)
                    .eq(ExaminationPaper::getEnable, 1))
                    .stream().collect(Collectors.toMap(ExaminationPaper::getCourse, z -> z, (z, y) -> z));
            ExaminationPaper sketch = map.getOrDefault(CourseEnum.SKETCH.getName(), new ExaminationPaper());
            vo.setSketch(PaperVO.builder().paperId(sketch.getId()).url(sketch.getImg()).build());
            ExaminationPaper writing = map.getOrDefault(CourseEnum.WRITING.getName(), new ExaminationPaper());
            vo.setWriting(PaperVO.builder().paperId(writing.getId()).url(writing.getImg()).build());
            ExaminationPaper color = map.getOrDefault(CourseEnum.COLOR.getName(), new ExaminationPaper());
            vo.setColor(PaperVO.builder().paperId(color.getId()).url(color.getImg()).build());
            ExaminationPaper compose = map.getOrDefault(CourseEnum.COMPOSE.getName(), new ExaminationPaper());
            vo.setCompose(PaperVO.builder().paperId(compose.getId()).url(compose.getImg()).build());
            return vo;
        }).collect(toList()));
        return page;
    }

    /**
     * Update boolean.
     *
     * @param bo the bo
     * @return the boolean
     */
    public boolean update(PaperBO bo) {
        ExaminationPaper info = new ExaminationPaper();
        info.setId(bo.getPaperId());
        info.setImg(bo.getUrl());
        info.setGrade(bo.getGrade());
        info.setScore(bo.getScore());
        info.setModifier(AuthTool.currentUser().getAccount());
        return examinationPaperService.updateById(info);
    }

    /**
     * Delete boolean.
     *
     * @param paperId the paper id
     * @return the boolean
     */
    public boolean delete(Long paperId) {
        ExaminationPaper info = new ExaminationPaper();
        info.setId(paperId);
        info.setEnable(false);
        info.setModifier(AuthTool.currentUser().getAccount());
        return examinationPaperService.updateById(info);
    }

    /**
     * Upload boolean.
     *
     * @param bo the bo
     * @return the boolean
     */
    public UploadVO upload(UploadPaperBO bo) {
        //二维码解析
        String account = AuthTool.currentUser().getAccount();
        String admissionTicketCode = resolving(bo.getUrl());
        ExaminationPaper examinationPaper = examinationPaperService.getOne(Wrappers.<ExaminationPaper>lambdaQuery().eq(ExaminationPaper::getCourse, bo.getCourse())
                .eq(ExaminationPaper::getAdmissionTicketCode, admissionTicketCode)
                .eq(ExaminationPaper::getEnable, 1));
        ExamineeInfo examineeInfo = examineeInfoService.getOne(Wrappers.<ExamineeInfo>lambdaQuery().eq(ExamineeInfo::getAdmissionTicketCode, admissionTicketCode)
                .eq(ExamineeInfo::getActivityStatus, 1));
        if (examineeInfo == null) {
            throw ArtException.buildException("未找到考生信息");
        }
        if (examinationPaper == null) {
            examinationPaper = new ExaminationPaper();
        }
        examinationPaper.setProvince(examineeInfo.getProvince());
        examinationPaper.setExamCode(examineeInfo.getExaminationRoomCode());
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            doSave(bo, examinationPaper, admissionTicketCode);
        } catch (Exception ex) {
            transactionManager.rollback(status);
            log.error("upload保存数据异常", ex);
            throw ArtException.buildException();
        }
        transactionManager.commit(status);
        UploadVO vo = new UploadVO();
        vo.setAdmissionTicketCode(examineeInfo.getAdmissionTicketCode());
        vo.setExamineeName(examineeInfo.getExamineeName());
        return vo;
    }

    /**
     * Do save boolean.
     *
     * @param bo                  the bo
     * @param examinationPaper    the examination paper
     * @param admissionTicketCode the admission ticket code
     * @return the boolean
     */
    public boolean doSave(UploadPaperBO bo, ExaminationPaper examinationPaper, String admissionTicketCode) {
        Assert.notNull(examinationPaper, "examinationPaper is not null");
        if (examinationPaper != null && examinationPaper.getId() != null) {
            ExaminationPaper examinationPaper1 = new ExaminationPaper();
            examinationPaper1.setId(examinationPaper.getId());
            examinationPaper1.setEnable(false);
            if (!examinationPaperService.updateById(examinationPaper1)) {
                throw ArtException.buildException();
            }
        }
        ExaminationPaper paper = new ExaminationPaper();
        paper.setImg(bo.getUrl());
        paper.setCourse(bo.getCourse());
        paper.setAdmissionTicketCode(admissionTicketCode);
        paper.setAdmissionTicketCode(admissionTicketCode);
        paper.setExamCode(examinationPaper.getExamCode());
        paper.setProvince(examinationPaper.getProvince());
        if (!examinationPaperService.save(paper)) {
            throw ArtException.buildException();
        }
        ExamineeInfo examineeInfo = new ExamineeInfo();
        //examineeInfo.setUpdateUserId();
        if (StringUtils.isNotBlank(bo.getCourse())) {
            if (StringUtils.equals(bo.getCourse(), CourseEnum.COLOR.getName())) {
                examineeInfo.setIsColor(true);
            } else if (StringUtils.equals(bo.getCourse(), CourseEnum.SKETCH.getName())) {
                examineeInfo.setIsSketch(true);
            } else if (StringUtils.equals(bo.getCourse(), CourseEnum.WRITING.getName())) {
                examineeInfo.setIsWriting(true);
            } else if (StringUtils.equals(bo.getCourse(), CourseEnum.COMPOSE.getName())) {
                examineeInfo.setIsCompose(true);
            } else {
                throw new ArtException(5101, "科目类型没找到");
            }
        }
        if (!examineeInfoService.update(examineeInfo, Wrappers.<ExamineeInfo>lambdaQuery()
                .eq(ExamineeInfo::getAdmissionTicketCode, admissionTicketCode))) {
            throw ArtException.buildException();
        }
        return true;
    }

    /**
     * Resolving string.
     *
     * @param url the url
     * @return the string
     */
    public String resolving(String url) {
        String context;
        try {
           /* HttpURLConnection httpUrl = (HttpURLConnection) new URL(url).openConnection();
            httpUrl.connect();
            File file = QRCodeUtil.inputStreamToFile(httpUrl.getInputStream(), UUID.randomUUID().toString() + "url.jpg");
            httpUrl.disconnect();*/
            long start = System.currentTimeMillis();
            //context = QRCodeUtil.decode(file, PositionEnum.UP_RIGHT.getCode());
            context = AliYunCode.decode(url);
            log.info("ts=[{}],context=[{}]", System.currentTimeMillis() - start, context);
            /*if (file.exists()) {
                file.delete();
            }*/
            if (StringUtils.isBlank(context)) {
                throw new ArtException(511, "二维码识别失败");
            }
            return context;
        } catch (Exception e) {
            log.error("upload", e);
            throw new ArtException(510, "二维码识别异常");
        }
    }

    /**
     * Agg paper agg vo.
     *
     * @return the paper agg vo
     */
    public PaperAggVO agg(GradeBO bo) {
        String account = AuthTool.currentUser().getAccount();
        PaperAggVO vo = new PaperAggVO();
        vo.setCount(examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNull(ExaminationPaper::getScore)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getAccount, account)
                .eq(ExaminationPaper::getEnable, 1).eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade())));
        vo.setDealCount(examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNotNull(ExaminationPaper::getScore)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getAccount, account).eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade())
                .eq(ExaminationPaper::getEnable, 1)));

        int count = examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNull(ExaminationPaper::getScore)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getEnable, 1).eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade()));
        int dealCount = examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNotNull(ExaminationPaper::getScore)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade())
                .eq(ExaminationPaper::getEnable, 1));

        vo.setTotal(defaultInteger(count) + defaultInteger(dealCount));
        if (StringUtils.isNotBlank(bo.getGrade())) {
            return vo;
        }
        List<Aggregation> aggregations = examinationPaperService.aggregation(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNotNull(ExaminationPaper::getScore).isNotNull(ExaminationPaper::getGrade)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getEnable, 1));
        if (CollectionUtils.isEmpty(aggregations)) {
            return vo;
        }
        Map<String, Aggregation> map = aggregations.stream().collect(Collectors.toMap(Aggregation::getGrade, z -> z, (z, y) -> z));
        List<Aggregation> aggregations1 = examinationPaperService.aggregation(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNull(ExaminationPaper::getScore)
                .isNotNull(ExaminationPaper::getGrade)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getEnable, 1));
        Map<String, Aggregation> map1 = aggregations1.stream().collect(Collectors.toMap(Aggregation::getGrade, z -> z, (z, y) -> z));
        Set<String> key = Sets.newHashSet();
        key.addAll(map.keySet());
        key.addAll(map1.keySet());
        vo.setStats(key.stream().map(x -> {
            PaperAggVO.StatsModelVO model = new PaperAggVO.StatsModelVO();
            model.setName(x);
            model.setDealCount(map.getOrDefault(x, new Aggregation()).getCount());
            model.setCount(map1.getOrDefault(x, new Aggregation()).getCount());
            model.setTotal(defaultInteger(vo.getCount()) + defaultInteger(vo.getDealCount()));
            return model;
        }).collect(toList()));
        vo.getStats().sort(Comparator.comparing(PaperAggVO.StatsModelVO::getName, Comparator.naturalOrder()));
        return vo;
    }

    /**
     * Grade list.
     *
     * @return the list
     */
    public List<PaperAggVO.StatsModelVO> grade(GradeBO bo) {
        String account = AuthTool.currentUser().getAccount();
        List<PaperAggVO.StatsModelVO> statsModelDTOS = Lists.newArrayList();
        List<Aggregation> aggregations1 = examinationPaperService.aggregation(Wrappers.<ExaminationPaper>lambdaQuery()
                .isNotNull(ExaminationPaper::getGrade)
                .eq(ExaminationPaper::getProvince,bo.getProvince())
                .eq(ExaminationPaper::getCourse,bo.getCourse())
                .eq(ExaminationPaper::getAccount, account)
                .eq(ExaminationPaper::getEnable, 1));
        if (CollectionUtils.isNotEmpty(aggregations1)) {
            statsModelDTOS.addAll(aggregations1.stream().map(x -> PaperAggVO.StatsModelVO.builder().name(x.getGrade()).total(x.getCount()).build()).collect(toList()));
        }
        statsModelDTOS.sort(Comparator.comparing(PaperAggVO.StatsModelVO::getName, Comparator.naturalOrder()));
        return statsModelDTOS;
    }

    /**
     * Query page.
     *
     * @param bo the bo
     * @return the page
     */
    public Page<PaperQueryVO> query(PaperQueryBO bo) {
        Page<PaperQueryVO> paperQueryVOPage = new Page<>(bo.getCurrent(), bo.getSize());
        String account = AuthTool.currentUser().getAccount();
        IPage<ExaminationPaper> paperIPage = examinationPaperService.page(new Page<>(bo.getCurrent(), bo.getSize()),
                Wrappers.<ExaminationPaper>lambdaQuery().eq(ExaminationPaper::getAccount, account)
                        .eq(notNullAndEmpty(bo.getGrade()), ExaminationPaper::getGrade, bo.getGrade())
                        .isNull(bo.getStatus() != null && bo.getStatus() == 0, ExaminationPaper::getScore)
                        .isNull(bo.getStatus() != null && bo.getStatus() == 1, ExaminationPaper::getGrade)
                        .eq(ExaminationPaper::getEnable, 1));
        if (paperIPage != null) {
            paperQueryVOPage.setTotal(paperIPage.getTotal());
            paperQueryVOPage.setRecords(examinationPaperConverter.dos2vos(paperIPage.getRecords()));
        }
        return paperQueryVOPage;
    }

    /**
     * Upload boolean.
     *
     * @param bo the bo
     * @return the boolean
     */
    public UploadVO scarnCode(UploadPaperBO bo) {
        String admissionTicketCode = bo.getAdmissionTicketCode();
        ExaminationPaper examinationPaper = examinationPaperService.getOne(Wrappers.<ExaminationPaper>lambdaQuery().eq(ExaminationPaper::getCourse, bo.getCourse())
                .eq(ExaminationPaper::getAdmissionTicketCode, admissionTicketCode)
                .eq(ExaminationPaper::getEnable, 1));
        ExamineeInfo examineeInfo = examineeInfoService.getOne(Wrappers.<ExamineeInfo>lambdaQuery().eq(ExamineeInfo::getAdmissionTicketCode, admissionTicketCode)
                .eq(ExamineeInfo::getActivityStatus, 1));
        if (examineeInfo == null) {
            throw ArtException.buildException("未找到考生信息");
        }
        if (examinationPaper == null) {
            examinationPaper = new ExaminationPaper();
        }
        examinationPaper.setProvince(examineeInfo.getProvince());
        examinationPaper.setExamCode(examineeInfo.getExaminationRoomCode());
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            doSave(bo, examinationPaper, admissionTicketCode);
        } catch (Exception ex) {
            transactionManager.rollback(status);
            log.error("upload保存数据异常", ex);
            throw ArtException.buildException();
        }
        transactionManager.commit(status);
        UploadVO vo = new UploadVO();
        vo.setAdmissionTicketCode(examineeInfo.getAdmissionTicketCode());
        vo.setExamineeName(examineeInfo.getExamineeName());
        return vo;
    }


    public List<PaperStatisticVO> queryPaperStatistic() {
        List<PaperStatisticVO> ret = new ArrayList<>();
        List<ProvinceExamineeCountVO> provinceExamineeCountVOS = examineeInfoMapper.queryProvinceExamineeCountVO();
        List<String> courses = ImmutableList.of("素描", "色彩", "速写", "设计");
        for (String c : courses) {
            ret.add(getPaperStatisticByCourse(c, provinceExamineeCountVOS));
        }
        return ret;
    }

    private PaperStatisticVO getPaperStatisticByCourse(String course, List<ProvinceExamineeCountVO> provinceExamineeCountVOS) {
        PaperStatisticVO paperStatisticVO = new PaperStatisticVO();
        paperStatisticVO.setCourse(course);
        Long paperTotalCount = 0L;
        List<String> provinces = rulerMapper.queryProvinceByCourse(course);
        Set<String> provinceSet = new HashSet<>(provinces);
        for (ProvinceExamineeCountVO p : provinceExamineeCountVOS) {
            if (provinceSet.contains(p.getProvince())) {
                paperTotalCount = paperTotalCount + p.getCnt();
            }
        }
        paperStatisticVO.setPaperTotalCount(paperTotalCount);
        paperStatisticVO.setAlreadyInDbCount(examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .eq(ExaminationPaper::getEnable, 1).eq(ExaminationPaper::getCourse, course)));
        return paperStatisticVO;
    }

    public Boolean finishReviewPaper() {
        // 判断paper表中grade和score是否都非空
        int notReviewPaperCount = examinationPaperService.count(Wrappers.<ExaminationPaper>lambdaQuery()
                .eq(ExaminationPaper::getEnable, 1)
                .isNull(ExaminationPaper::getGrade)
                .or()
                .isNull(ExaminationPaper::getCourse));
        if (notReviewPaperCount != 0) {
            throw new ArtException(CommonErrorCodeEnum.REVIEW_PAPER_NOT_FINISH);
        }

        Constants constant = iConstantsService.getOne(Wrappers.<Constants>lambdaQuery()
                .eq(Constants::getLockKey, "review_status")
                .eq(Constants::getLockValue, "start"));

        if (constant == null) {
            throw new ArtException(CommonErrorCodeEnum.REVIEW_PAPER_NOT_START);
        }

        // 总分画室内排名
        List<ExamineeInfo> tempExaminees = new ArrayList<>();
        List<ExamineeInfo> examineeInfos = examineeInfoService.list();
        Map<String, List<ExamineeInfo>> totalScoreRankMap = examineeInfos.stream()
                .collect(Collectors.groupingBy(ExamineeInfo::getStudioCode,
                        Collectors.collectingAndThen(toList(),
                                e -> e.stream()
                                        .sorted(Comparator.comparingLong(ExamineeInfo::getTotalScore))
                                        .collect(toList()))));
        totalScoreRankMap.forEach((key, value) -> tempExaminees.addAll(setRankOfTotalScore(value)));
        // 总分省内排名
        totalScoreRankMap = tempExaminees.stream()
                .collect(Collectors.groupingBy(ExamineeInfo::getProvinceCode,
                        Collectors.collectingAndThen(toList(),
                                e -> e.stream()
                                        .sorted(Comparator.comparingLong(ExamineeInfo::getTotalScore))
                                        .collect(toList()))));
        totalScoreRankMap.forEach((key, value) -> tempExaminees.addAll(setRankInProvinceOfTotalScore(value)));
        examineeInfoService.saveBatch(tempExaminees);

        constant = new Constants();
        constant.setLockKey("review_status");
        constant.setLockValue("finish");
        iConstantsService.update(constant, Wrappers.<Constants>lambdaQuery().eq(Constants::getLockKey, "review_status"));
        return true;
    }

    private List<ExamineeInfo> setRankOfTotalScore(List<ExamineeInfo> examineeInfos) {
        if (examineeInfos != null && !examineeInfos.isEmpty()) {
            int len = examineeInfos.size();
            for (int i = 0; i < len; i++) {
                examineeInfos.get(i).setRankInStudio(i + 1);
            }
        }
        return examineeInfos;
    }

    private List<ExamineeInfo> setRankInProvinceOfTotalScore(List<ExamineeInfo> examineeInfos) {
        if (examineeInfos != null && !examineeInfos.isEmpty()) {
            int len = examineeInfos.size();
            for (int i = 0; i < len; i++) {
                examineeInfos.get(i).setRankInProvince((long) i + 1);
            }
        }
        return examineeInfos;
    }

    public Boolean startReviewPaper() {
        Constants constant = iConstantsService.getOne(Wrappers.<Constants>lambdaQuery()
                .eq(Constants::getLockKey, "review_status"));
        if (constant != null) {
            constant.setLockValue("start");
            iConstantsService.update(Wrappers.<Constants>lambdaQuery().eq(Constants::getLockKey, "review_status"));
        }
        constant = new Constants();
        constant.setLockKey("review_status");
        constant.setLockValue("start");
        iConstantsService.save(constant);
        return true;
    }


}
